import panelBase from "../base/panelBase";
import { talkData } from "../configData/talkData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class talkBox extends panelBase {

    @property(cc.Label)
    Label:cc.Label = null;

    private _curTalkData:any = null;
    private _curTalkIndex:number = 0; //对话索引
    private _curRecordIndex:number = 0;  //单条记录索引

    onLoad()
    {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouch, this);
    }

    onTouch()
    {
        this.PopRecord();
    }

    open(index:number)
    {
        this._curTalkIndex = index;
        this._curTalkData = talkData[this._curTalkIndex]
        this.PopRecord();
    }

    PopRecord()
    {
        if(!this._curTalkData[this._curRecordIndex])
        {
            this.close();
            return;
        }

        this.Label.string = this._curTalkData[this._curRecordIndex].des;
        this._curRecordIndex++;
    }
}
